package com.karlis.report;

import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.usermodel.CellStyle;

import com.karlis.domain.Item;
import com.karlis.domain.Warehouse;

public class FillManager {
	
	public static void fillReport(HSSFSheet worksheet, int startRowIndex, int startColIndex, List<Warehouse> datasource) {
		  // Row offset
		  startRowIndex += 2;
		   
		  // Create cell style for the body
		  HSSFCellStyle bodyCellStyle = worksheet.getWorkbook().createCellStyle();
		  bodyCellStyle.setAlignment(CellStyle.ALIGN_CENTER);
		  bodyCellStyle.setWrapText(true);
		   
		  // Create body
		  for (int i=startRowIndex; i+startRowIndex-2< datasource.size()+2; i++) {
		   // Create a new row
		   HSSFRow row = worksheet.createRow((short) i+1);
		 
		   // Retrieve the id value
		   HSSFCell cell1 = row.createCell(startColIndex+0);
		   cell1.setCellValue(datasource.get(i-2).getId());
		   cell1.setCellStyle(bodyCellStyle);
		 
		   // Retrieve the brand value
		   HSSFCell cell2 = row.createCell(startColIndex+1);
		   cell2.setCellValue(datasource.get(i-2).getName());
		   cell2.setCellStyle(bodyCellStyle);
		 
		   // Retrieve the model value
		   HSSFCell cell3 = row.createCell(startColIndex+2);
		   cell3.setCellValue(datasource.get(i-2).getAddress());
		   cell3.setCellStyle(bodyCellStyle);
		 
		   // Retrieve the maximum power value
		   HSSFCell cell4 = row.createCell(startColIndex+3);
		   cell4.setCellValue(datasource.get(i-2).getManager());
		   cell4.setCellStyle(bodyCellStyle);
		  }
		 }

	public static void fillReportitem(HSSFSheet worksheet, int startRowIndex, int startColIndex, List<Item> itemsource) {
		startRowIndex += 2;
		   
		  // Create cell style for the body
		  HSSFCellStyle bodyCellStyle = worksheet.getWorkbook().createCellStyle();
		  bodyCellStyle.setAlignment(CellStyle.ALIGN_CENTER);
		  bodyCellStyle.setWrapText(true);
		   
		  // Create body
		  for (int i=startRowIndex; i+startRowIndex-2< itemsource.size()+2; i++) {
		   // Create a new row
		   HSSFRow row = worksheet.getRow((short) i+1);
		 
/*		   // Retrieve the id value
		   HSSFCell cell5 = row.createCell(startColIndex+4);
		   cell5.setCellValue(itemsource.get(i-2).getId());
		   cell5.setCellStyle(bodyCellStyle); */
		 
		   // Retrieve the brand value
		   HSSFCell cell6 = row.createCell(startColIndex+4);
		   cell6.setCellValue(itemsource.get(i-2).getName());
		   cell6.setCellStyle(bodyCellStyle);
		 
		   // Retrieve the model value
		   HSSFCell cell7 = row.createCell(startColIndex+5);
		   cell7.setCellValue(itemsource.get(i-2).getNumber());
		   cell7.setCellStyle(bodyCellStyle);
		  }
		 }
		
	}
